package com.gvsoft.analyse.order;

import com.gvsoft.analyse.inf.IOrder;

/**
 * Created with IntelliJ IDEA.
 * ProjectName:gvMsgRouting
 * Author: zhaoqiubo
 * Date: 15/8/7
 * Time: 下午2:36
 * Desc: 错误指令类，有待完善
 */
public class ErrorOrder extends Order implements IOrder {


    private String errCode;
    private String errMsg;
    private String errBody;

    public final static String HEADER = "E";
    public final static String INVAILD_REQ_CODE = "10001";
    public final static String INVAILD_REQ_MSG = "无效请求！";

    /**
     * 有时异常情况，可能解析不出客户端的rid，此时将rid定义为0
     * @param errCode
     * @param errMsg
     */
    public void initErrorOrder(String errCode, String errMsg) {
        this.header = HEADER;
        this.errCode = errCode;
        this.errMsg = errMsg;
        this.rid = "0";//没有客户端的rid则默认为0；
        StringBuffer sb = new StringBuffer();
        sb.append("{\"errCode\":").append(errCode).append(",\"errMsg\":").append(errMsg).append("}");
        this.errBody = sb.toString();
    }

    /**
     * 构造函数
     * @param rid 客户端发出的rid
     * @param errCode
     * @param errMsg
     */
    public void initErrorOrder(String rid, String errCode, String errMsg) {
        this.header = HEADER;
        this.errCode = errCode;
        this.errMsg = errMsg;
        this.rid = rid;
        StringBuffer sb = new StringBuffer();
        sb.append("{\"errCode\":").append(errCode).append(",\"errMsg\":").append(errMsg).append("}");
        this.errBody = sb.toString();
    }

    public String getErrCode() {
        return errCode;
    }

    public void setErrCode(String errCode) {
        this.errCode = errCode;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    public String getErrBody() {
        return errBody;
    }

    public void setErrBody(String errBody) {
        this.errBody = errBody;
    }

    public String generateOrderStr() {

        StringBuffer sb = new StringBuffer();
        sb.append(HEADER).append("|").append(this.getRid())
                .append("|").append(this.getErrBody());
        return sb.toString();
    }
}
